<template>
  <div class="headerTitle">
    <div :class="titleClickIndex === index ? 'isTitleClick' : ''" v-for="(titleData, index) in titleData"  :key="index"
         @click="titleClick(index,titleData.path)">
      {{ titleData.name }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'TitleHeader',
  props: ['titleData'],
  data () {
    return {
      // 点击标题索引
      // eslint-disable-next-line vue/no-dupe-keys
      titleClickIndex: 0
    }
  },
  methods: {
    titleClick (index, patch) {
      // if (this.$route.path !== patch) {
      //   // 进行导航操作
      //   this.$router.replace(patch)
      //   // eslint-disable-next-line vue/no-mutating-props
      this.titleClickIndex = index
      //   console.log(this.titleClickIndex)
      // }
      this.$parent.currentComponent = patch
    }
  }
}
</script>

<style scoped>
/* 点击标题的样式 */
.isTitleClick {
  color: rgb(39, 140, 255);
  border-bottom: 1px solid rgb(39, 140, 255);
  white-space: nowrap;
}
.isTitleClick :hover{
  color: rgb(39, 140, 255);
  border-bottom: 1px solid rgb(39, 140, 255);
  white-space: nowrap;
}
.headerTitle {
  border-bottom: 1px solid #f8f8f8;
  box-shadow: 0px 4px 4px #f8f8f8;
  transition: border-color 0.3s; /* 添加过渡效果 */
  display: flex;
}
.headerTitle div:not(.isTitleClick):hover{
  /* CSS 样式 */
  color: rgb(39, 140, 255);
}
.headerTitle>div {
  cursor: pointer;
  height: 30px;
  width: 100px;
  text-align: center;
}

.headerTitle > div {
  border-right: 1px solid #f8f8f8;
}

.headerTitle > div:last-child {
  border-right: none;
}
</style>
